<%--
  Created by IntelliJ IDEA.
  User: 小杭呀~ 分页查询的实现
  Date: 2021/5/11
  Time: 15:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>>
<html>
  <head>
    <title>分页查询</title>
  </head>
  <body>

  <table border="1px" align="center">
    <tr>
      <th>货号</th> <th>名称</th>  <th>价格</th> <th>库存</th>
    </tr>
<%--遍历splist集合--%>
    <c:forEach items="${spList}" var="sp">
      <tr>
        <td>${sp.id}</td> <td>${sp.name}</td> <td>${sp.price}</td> <td>${sp.number}</td>
      </tr>

    </c:forEach>




  </table>

  <div align="center">
    

    <a href="show?page=1">首页</a>
    
    
<%--    判断还能不能点击下一页--%>
    
    <c:if test="${page>1}"  >
      <a href="show?page=${page-1}">上一页</a>
    </c:if>

    <span>${page}/${sumPage}</span>

    <c:if test="${page<sumPage}"  >
      <a href="show?page=${page+1}">下一页</a>
    </c:if>
    <a href="show?page=${sumPage}">末尾</a>

  </div>

<%--  如果用户直接访问了index是没有数据的，需要自动发送请求--%>
  <c:if test="${empty spList}">
    <jsp:forward page="show"></jsp:forward>
  </c:if>


  </body>
</html>
